package com.company.exam7;

/**
 * 第7题  利用多线程模拟银行存钱与取钱操作。（30分）
 */
public class Account {

    private  String aid;
    private double balance;//余额


    //取款
    public synchronized void draw(double money){
        if(balance>=money){
            System.out.println("当前线程："+Thread.currentThread().getName()+"取款成功，取款金额："+money);
            //修改账户余额
            balance=balance-money;
            System.out.println("余额："+balance);
        }else{
            System.out.println("余额不足，取款失败");
        }
    }




    public  Account(String aid,double balance){
        this.aid=aid;
        this.balance=balance;
    }

    public String getAid() {
        return aid;
    }
    public void setAid(String aid) {
        this.aid = aid;
    }
    public double getBalance() {
        return balance;
    }
    public void setBalance(double balance) {
        this.balance = balance;
    }

}

